<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>选择物料</title>
		<meta name="viewport" content=" height=device-height,
			          width=device-width,
			          initial-scale=1.0,
			          minimum-scale=1.0,
			          maximum-scale=1.0
			          user-scalable=no" />
		<script type="text/javascript" src="../js/jquery.min.js" charset="utf-8"></script>
		<script type="text/javascript">
			$(function() {
				var token = localStorage.getItem("token");
				var ip = localStorage.getItem("ip");
				$.ajax({
					type: 'post', //类型
					url: ip + 'bom/list', //请求路径
					contentType: 'application/x-www-form-urlencoded', //默认
					dataType: 'json', //返回数据类型  可以是text：字符串  可以是json：json对象
					data: {
						'token': token,
					}, //数据
					success: function(result) {
						if(result.code == 200) {
							for(var Key in result.data) {
								var bomId = result.data[Key].id;
								var bomNum = result.data[Key].bomNum;
								var partsName = result.data[Key].partsName;
								var bomIds = localStorage.getItem("sums");
								var bomNums = localStorage.getItem("unms");
								var id = JSON.parse(bomIds);
								var num = JSON.parse(bomNums);
								for(var crux in id) {
									if(id[crux] == bomId) {
										var txts = '<tr><td><p><input name="item" type="checkbox" checked="checked" value="' + bomId + '"/>' + partsName + bomNum;
										txts = txts + '<input type="ted" name="numitem" style="width: 15%;margin-left:70%;" value="'+num[crux]+'"/>';
										txts = txts + '</p></td></tr>';
									}else{
										var txts = '<tr><td><p><input name="item" type="checkbox" value="' + bomId + '"/>' + partsName + bomNum;
										txts = txts + '<input type="ted" name="numitem" style="width: 15%;margin-left:70%;"/>';
										txts = txts + '</p></td></tr>';
									}
								}

								$(".bom-ta").append(txts);
							}
						} else {
							alert('获取数据异常,请重新登录');
							//window.location.href='Login.html';
						}
					},
					error: function(data) { //若果传过来的数据为空
					}
				});
			});

			function calculateMoney() {
				var sum = [];
				var unm = [];
				var chkItems = document.getElementsByName("item");
				var numItems = document.getElementsByName("numitem");
				for(var i = 0; i < chkItems.length; i++) {
					if(chkItems[i].checked) {
						sum[i] = parseInt(chkItems[i].value.trim());
						unm[i] = parseInt(numItems[i].value.trim());
					}
				}
				var sums = JSON.stringify(sum);
				localStorage.setItem("sums", sums);
				var unms = JSON.stringify(unm);
				localStorage.setItem("unms", unms);
				window.location.href = 'supplyProductsAdd.html';
			}
		</script>
	</head>

	<body>
		<font>请选择所需的物料</font>
		<input type="button" value="提交" onclick="calculateMoney()" style="width: 20%; margin-left: 30%;" />
		<table width="100%" class="bom-ta" border="1" style="border-collapse: collapse;">
		</table>
	</body>

</html>